Obsidian Charts Plugin 使用表格创建图表

1 背景知识

可以通过 [[#2 引用表格]]或者 [[#3 替换表格]] 两种方式创建图表。这也是我比较喜欢的一种方式。

Warning

[[#3 替换表格]] 是将表格转换为图表,请慎重使用。

2 引用表格

准备一个表格,并增加标签 ^table 如下所示。

|       | col1 | col2 | col3 |
| ----- | ---- | ---- | ---- |
| Data1 | 1    | 2    | 3.33 |
| Data2 | 3    | 2    | 1    |
| Data3 | 3    | 4    | 2    |
^table
col1 col2 col3
Data1 1 2 3.33
Data2 3 2 1
Data3 3 4 2

2.1 创建折线图

选项 说明
type 图表类型
id 标签名称,未加 file 选项时从当前文件中寻找表格。
layout rows:表示行的值作为坐标轴 Y 的值,column:表示列的值作为坐标轴 Y 的值。
width 图表宽度。
beginAtZero 坐标是否强制从0 开始。
```chart
type: line
id: table 
layout: rows  
width: 40%
beginAtZero: true
```
type: line
id: table 
layout: rows  
width: 40%
beginAtZero: true

2.2 创建柱状图

选项 说明
type 图表类型
id 标签名称,未加 file 选项时从当前文件中寻找表格。
layout rows:表示行的值作为坐标轴 Y 的值,column:表示列的值作为坐标轴 Y 的值。
width 图表宽度。
beginAtZero 坐标是否强制从0 开始。
file 表示要从哪个文档中寻找 table 标签。
select 当layout为rows 时,表示选择是哪一行。当layout为 column 时,表示选择的是哪一列。
```chart
type: bar
id: table
file: Obsidian Charts Plugin 使用表格创建图表
layout: rows
width: 40%
beginAtZero: true
select: [Data2]
```
type: bar
id: table
file: Obsidian Charts Plugin 使用表格创建图表
layout: rows
width: 40%
beginAtZero: true
select: [Data2]

3 替换表格

替换表格将表格转换为图表,具体步骤如下:

  1. 将表格全选。
  2. 使用 CTRL+P 打开命令面板。选择 Obsidian Charts:Create Chart from Table (Column oriented Layout) ,即可将表格转换为图表模式。

Obsidan Charts 替换表格

3.1 替换之前

col1 col2 col3
Data1 1 2 3.33
Data2 3 2 1
Data3 3 4 2

3.2 替换之后

type: bar
labels: [Data1,Data2,Data3]
series:
  - title: col1
    data: [1,3,3]
  - title: col2
    data: [2,2,4]
  - title: col3
    data: [3.33,1,2]
width: 80%
beginAtZero: true